﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ZquenceStudio3Host.DspPlugins.Synthesizers.Nodesizer.Engine.Modules.HighLevel
{
    /// <summary>
    /// Reference: http://stackoverflow.com/questions/8079526/lowpass-and-high-pass-filter-in-c-sharp
    /// </summary>
    [ModuleDisplay("LowPass")]
    class LowPassModule : BasePassModule
    {
        public LowPassModule(ModuleManager manager)
            : base(manager)
        {
        }

        protected override void InitializeLowPass(double frequency, int sampleRate, double resonance)
        {
            this.resonance = resonance;
            this.frequency = frequency;
            this.sampleRate = sampleRate;
            
            c = 1.0f / (float)Math.Tan(Math.PI * frequency / sampleRate);
            a1 = 1.0f / (1.0f + resonance * c + c * c);
            a2 = 2f * a1;
            a3 = a1;
            b1 = 2.0f * (1.0f - c * c) * a1;
            b2 = (1.0f - resonance * c + c * c) * a1;
        }
    }
}
